<?php
	if(!isset($rootdir)) $rootdir = "/home/nrb62281/public_html";
	include_once($rootdir . "/DataObjects/characterData.php");
	include_once($rootdir . "/DataObjects/professionData.php");
	
	class nathansinfodbDataSource{
		private $dataConnection, $isConnected;
		function __construct(){
			$this->isConnected = 0;
		}
		function __destruct(){
			$this->disconnect();
		}
		
		// data retrieval functions
		public function getCharacter($characterName, $realmName, $region){
			// create character object
			// find character
			// populate character object (if found)
			// return character object
		}
		public function isCharacterRecent($characterName, $realmName, $region, $characterTimeout){
			// find character
			// get date from character entry
			// get current date
			// compare current date to date of entry + timeout
			// if current date is newer, return false
			// else, return true
		}
		public function getCharacterTimeout(){
			// find character timeout setting from DB
		}
		public function setCharacterTimeout(){
			// validate the character timeout setting in the DB
			// if valid, continue, if not, return false
			// set the character timeout setting in the DB
			// return true
		}
		
		// DB maint functions
		public function connect(){
			$loginFilename = "nathansinfodbloginfo.txt";
			if(file_exists($loginFilename)){
				$filecontents = file($loginFilename);
				$dbLoginInfo = array();
				foreach($filecontents as $row){
					$explodedRow = explode($row,"=");
					if(count($explodedRow) > 1){
						$dbLoginInfo[$explodedRow[0]] = $explodedRow[1];
					}
				}
				if(isset()&&isset()&&isset()&&isset()){
				
					$this->dataConnection = mysql_connect($dbLoginInfo["host"], $dbLoginInfo["user"], $dbLoginInfo["pass"]) or return false;
					if(!$dataConnection){
						return false;
					}
					$selectedTest = mysql_select_db($dbLoginInfo["dbname"]);
					if(!$selectedTest){
						return false;
					}
					return true;
				}
			}
			return false;
		}
		public function disconnect(){
			if(($isConnected)||($dataConnection)){
				mysql_close($dataConnection);
			}
		}
		public function isConnected(){
			// returns connected state
			return $this->isConnected;
		}
		
		// data access functions
		public function storeCharacter($newCharacter){
			// takes characterData object
			// returns TRUE on success or FALSE on failure
			
			$newCharacter->getNameCharacter();
			$newCharacter->getNamePrefix();
			$newCharacter->getNameSuffix();
			$newCharacter->getLevel();
			$newCharacter->getClass();
			$newCharacter->getAchievementPoints();
			$newCharacter->getGuildName();
			$newCharacter->getLifetimePVPKills();
		}
	}
?>